package com.itheima.edu.info.manager;

import com.itheima.edu.info.manager.service.StudentService;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class StudentServerApplication {
    public static void main(String[] args) throws IOException {
        //创建服务器端套接字serverSocket
        ServerSocket serverSocket = new ServerSocket(10088);
        //创建ThreadPoolExecutor线程池
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
                3,
                10,
                60,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        while (true) {
            //1. 监听客户端连接(注意:套接字必须一致)
            Socket socket = serverSocket.accept();
            //2. 创建一个线程任务,去处理这个socket请求
            StudentService service = new StudentService(socket);
            //开启线程任务
            threadPool.submit(service);
        }

    }
}
